package TechStuff;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import TechStuff.ClientInterface;
import TechStuff.RmiStarter;


public class ClientStarter extends RmiStarter {
	private int id;
	private Client client;
	
	public ClientStarter(int id, Client client)
	{
		super(ClientInterface.class);
		this.client = client;
		this.id = id;
		doCustomRmiHandling();
	}

	@Override
	public void doCustomRmiHandling() {
		try {
			ClientInterface obj = client;
			ClientInterface stub = (ClientInterface) UnicastRemoteObject.exportObject(obj, 0);

		    // Bind the remote object's stub in the registry
		    Registry registry = LocateRegistry.getRegistry();
		    String name = ClientInterface.name + id;
		    registry.bind(name, stub);

		    System.err.println(name + " ready");
		} catch (Exception e) {
		    System.err.println("ClientInterface exception: " + e.toString());
		    e.printStackTrace();
		}	
		
	}
	

}
